﻿using System;

namespace _54_使用_运算符将两个对象的属性相值相当_运算符
{
    class Program
    {
        static void Main(string[] args)
        {
            Test t1 = new Test { Val1 = 5, Val2 = 9 };
            Test t2 = new Test { Val1 = 2, Val2 = 6 };

            //使用运算符+号将以上两个变量进行相加
            int result = t1 + t2;
            Console.WriteLine("两个对象的属性值相加的结果：{0}", result);
        }
    }

    class Test
    {
        public int Val1 { get; set; }
        public int Val2 { get; set; }

        //必须有公共属性才可以调用
        public static int operator + (Test a,Test b)
        {
            return a.Val1 + a.Val2 + b.Val1 + b.Val2;
        }
    }

    
}
